package com.software.graduationproject.modules.food.web;

import com.baomidou.mybatisplus.core.metadata.Page;

import com.software.graduationproject.commons.select.Select;
import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.food.object.FoodCommentVo;
import com.software.graduationproject.modules.food.object.FoodVo;
import com.software.graduationproject.modules.food.service.FoodService;
import com.software.graduationproject.modules.food.object.FoodCreateQo;

import com.v2coding.validate.CreateGroup;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * FoodController : 食品表
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/Food/Food")
@Api(value = "API - 食品表", tags = {"食品表接口"})
public class FoodController {

    @Autowired
    private FoodService foodService;

    @PostMapping("/create")
    @ApiOperation("新增食品")
    public Result createQo(@RequestBody @Validated(CreateGroup.class) FoodCreateQo foodCreateQo) {
        foodService.createQo(foodCreateQo);
        return Results.success();
    }

    @GetMapping("/select")
    @ApiOperation("查询食品")
    public Result selectVo(Long id) {
        FoodVo foodVo = foodService.selectVo(id);
        return Results.success(foodVo);
    }

    @GetMapping("/selectList")
    @ApiOperation("搜索框查询食品列表")
    public Result<List<FoodVo>> selectListVo(@ApiIgnore Select select) {
        List<FoodVo> foodVoList = foodService.selectListVo(select);
        return Results.success(foodVoList);
    }

    @GetMapping("/selectFoodComment")
    @ApiOperation("查询食品评价")
    public Result<FoodCommentVo> selectFoodComment(Long id) {
        FoodCommentVo foodCommentVo = foodService.selectFoodComment(id);
        return Results.success(foodCommentVo);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询食品表分页")
    public Result<Page<FoodVo>> selectPageVo(@ApiIgnore Select select) {
        Page<FoodVo> foodVoPage = foodService.selectPageVo(select);
        return Results.success(foodVoPage);
    }

    @GetMapping("/searchList")
    @ApiOperation("查询食品表列表")
    public Result<List<FoodVo>> searchAllBySelect(@ApiIgnore Select select) {
        List<FoodVo> foodVoList = foodService.searchAllBySelect(select);
        return Results.success(foodVoList);
    }
}
